package com.lyx.db137.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lyx.db137.common.R;
import com.lyx.db137.entity.Rolemenu;
import com.lyx.db137.service.RolemenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: zero domain
 * @CreateTime: 2024/12/31 11:19
 * @Description: 角色菜单中间表
 * @Version: 1.0
 */
@CrossOrigin(origins = "*")
@RestController
public class RoleMenuController {
    @Autowired
    RolemenuService rolemenuService;
    @GetMapping("selectRoleMenuByRoleId/{roleid}")
    public R selectRoleMenuByRoleId(@PathVariable("roleid")int roleid){
        QueryWrapper<Rolemenu> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("roleid",roleid);
        List<Rolemenu> rolemenuList = this.rolemenuService.list(queryWrapper);
        return new R().add("rolemenuList",rolemenuList);
    }

    /**
     * 根据角色id修改菜单id集合
     * @param
     * @param
     * @return
     */
    @PostMapping("updateRoleMenuId")
    public R updateRoleMenuId(@RequestBody Map<String,Object>map){
        int roleid=Integer.parseInt(map.get("roleid")+"");
        List<Integer> listMenu =(List<Integer>) map.get("listMenu");
        boolean boo= this.rolemenuService.updateRoleMenuId(roleid,listMenu);
        return new R().add("boo",boo);
    }
}
